nextRound
TechnologiesCoding ProblemsBookmarksLearning Paths
nextRound
TechnologiesCoding ProblemsBookmarksLearning Paths
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

TOPIC OVERVIEW

javascript/Garbage Collector

How V8 decides what memory to reclaim, and when.

10 QuestionsExpertHigh Priority ~13 min read

JavaScript manages memory automatically, and the core question the garbage collector answers is reachability, not lifetime: an object is kept alive as long as something can still reach it, starting from root references (global variables, the current call stack) and following every reference outward. Anything unreachable from those roots is garbage, regardless of how recently it was created or used.

V8's collector isn't one algorithm — it splits the heap into a young generation (most objects die young, so this is collected frequently with a fast copying algorithm called Scavenger) and an old generation (long-lived objects, collected less often using mark-sweep-compact). Much of this work happens incrementally or concurrently with your code running, specifically to avoid long 'stop-the-world' pauses that would freeze the page. Memory leaks in JS almost always come down to something unintentionally staying reachable — forgotten timers, detached DOM nodes still referenced from JS, or closures holding onto more scope than they need.

What you'll walk away knowing

Why reachability, not lifetime, determines what gets collected
How the young and old generations differ, and why V8 uses different algorithms for each
What causes real-world memory leaks in JS: forgotten listeners/timers, detached DOM nodes, oversized closures
What a 'stop-the-world' pause is, and how incremental/concurrent GC tries to avoid it
1What is a Memory Leak, and how do you detect one?Intermediate2What is the difference between stack and heap memory?Intermediate3What causes memory leaks in JavaScript?Intermediate4What is garbage collection and how does V8 implement it?Intermediate5How does memory management work in JS engines?Intermediate6How does the "Mark-and-Sweep" algorithm work?Intermediate7Explain Generational Garbage Collection (Young vs. Old Generation).Intermediate8What is the "Write Barrier" in Garbage Collection?Intermediate9How do WeakMap and WeakSet help with Garbage Collection?Intermediate
All Topics
1
Basics
Data Types
Functions
Objects
2
Engine
JIT
V8
Event Loop and Runtime
Concurrency and Threading
Bytecode and Parsing
Execution Context
Garbage Collector
3
this
Call Apply Bind
Closure
Error Handling
4
String Operations
Array Operations
Iterator and Generator
Modules
5
Events
Promises
Web Workers
Web Sockets
6
Functional Programming
Currying
Higher Order Functions
Memoisation
7
ES6 Classes
ES6
PWA
Web Assembly
Browser APIS
8
Security
Code
Polyfills
Sharethis topic

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.